<?php
namespace app\front\service\v2;
use app\front\model\Userinfo as UserinfoModel;
use app\front\model\Flag as FlagModel;
use app\front\model\WithdrawOrder as WithdraworderModel;
use app\front\service\GetMsgService;
class Outside extends GetMsgService
{
    private static $_instance;
    
    //private 构造函数
    private function __construct() {
        // echo " I'm construct! process id is " . getmypid() . " and thread id is " . Thread::getCurrentThreadId() . "\n";
    }
    
    private function __clone() {
        //    echo " I'm clone! process id is " . getmypid() . " and thread id is " . Thread::getCurrentThreadId() . "\n";
    }
    
    //单例方法访问类实例
    public static function getInstance() {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }  
    
    /**
     * 函数用途描述 :检查一分钟内是否有刷新记录
     * @date: 2018年6月15日 上午8:45:25
     * @author: 孙洪亮
     * @param:  提现人姓名
     * @return: 有记录True 没 FALSE
     */
    public function checkServiceTimer(){
        $starttime = mktime(date('H'),date('i')-30,date('s'), date('m'),date('d'),date('Y'));
        $endtime = mktime(date('H'),date('i'),date('s'), date('m'),date('d'),date('Y'));
        $starttime= date("Y-m-d H:i:s",$starttime);
        $endtime= date("Y-m-d H:i:s",$endtime);
        $res= FlagModel::where("create_time >='$starttime' and create_time <='$endtime'")->select();
        $res= json_decode(json_encode($res),true);
        if(count($res)>=1){
            return true;
        }else{
            return false;
        }
    }
    
    /**
    * 函数用途描述 :向FLAG插入记录 此方法是检测服务器定时器的辅助方法
    * @date: 2018年6月20日 上午10:36:54
    * @author: 孙洪亮
    * @param:  null
    * @return: null
    */
    public function insertFlag(){
        $params=[
          'flag'=>1  ,
            'create_time'=>date("Y-m-d H:i:s", time())
        ];
        FlagModel::create($params);
    }
    
    public function TodayTaskPayNum()
    {
        $name=input('param.name');
        $starttime = strtotime(date("Y-m-d 00:00:00"));
        $starttime = date("Y-m-d H:i:s", $starttime);
        $endtime = strtotime(date("Y-m-d 23:59:59"));
        $endtime = date("Y-m-d H:i:s", $endtime);
        $starttime = strtotime($starttime);
        $endtime = strtotime($endtime);
        $TodayTaskPayNum = count(WithdraworderModel::where("create_time >='$starttime' and create_time <='$endtime'and name='$name'and status=1")->select());
        if ($TodayTaskPayNum >= config('MemberWithdrawNum')) {
            echo json_encode("每日提现次数不能超过".config('MemberWithdrawNum')."次！");
        } else {
            echo json_encode("success");
        }
    }
    
    /**
     * 函数用途描述 :用来在分公司添加商铺时检查微信ID是否正确
     * @date: 2018年6月15日 下午8:25:06
     * @author: 孙洪亮
     * @param:  null
     * @return: null
     */
    public function checkIDIsExist(){
        $id=input('param.weixin');
        $isExist=count(UserinfoModel::where('id',$id)->find());
        if($isExist==1){
            if(preg_match("/^\d*$/",$id)){
                echo json_encode("success");
            }else{
                echo json_encode("会员ID：'".$id."'不存在！正确应为纯数字的ID号如：‘1314’\n提示：会员ID号可在公众号菜单的‘个人中心’查看。");
            }
        }else{
            echo json_encode("会员ID：'".$id."'不存在！正确应为纯数字的ID号如：‘1314’\n提示：会员ID号可在公众号菜单的‘个人中心’查看。");
        }
    }
    
}


